﻿using System;
using SEXY;
using UnityEngine;
using UnityEngine.UI;

namespace Studio
{
	// Token: 0x0200054C RID: 1356
	[Serializable]
	public class UI_ColorInfo : MonoBehaviour
	{
		// Token: 0x060022A5 RID: 8869 RVA: 0x000D0720 File Offset: 0x000CE920
		public Color GetColorRGB()
		{
			return new Color(this.colorValue[3], this.colorValue[4], this.colorValue[5], this.colorValue[6]);
		}

		// Token: 0x060022A6 RID: 8870 RVA: 0x000D0748 File Offset: 0x000CE948
		public HsvColor GetColorHSV()
		{
			return new HsvColor(this.colorValue[0], this.colorValue[1], this.colorValue[2]);
		}

		// Token: 0x060022A7 RID: 8871 RVA: 0x000D0768 File Offset: 0x000CE968
		public float GetColorAlpha()
		{
			return this.colorValue[6];
		}

		// Token: 0x060022A8 RID: 8872 RVA: 0x000D0774 File Offset: 0x000CE974
		protected float[] GetRateRGB()
		{
			return new float[]
			{
				this.colorValue[3],
				this.colorValue[4],
				this.colorValue[5],
				this.colorValue[6]
			};
		}

		// Token: 0x060022A9 RID: 8873 RVA: 0x000D07B8 File Offset: 0x000CE9B8
		protected float[] GetRateHSV()
		{
			return new float[]
			{
				Mathf.InverseLerp(0f, 360f, this.colorValue[0]),
				this.colorValue[1],
				this.colorValue[2]
			};
		}

		// Token: 0x060022AA RID: 8874 RVA: 0x000D0800 File Offset: 0x000CEA00
		protected virtual void Init()
		{
			this.colorValue[0] = 0f;
			this.colorValue[1] = 0f;
			this.colorValue[2] = 1f;
			this.colorValue[3] = 1f;
			this.colorValue[4] = 1f;
			this.colorValue[5] = 1f;
			this.colorValue[6] = 1f;
			this.colorMenu = (this as UI_ColorMenu);
			this.colorPicker = (this as UI_ColorPicker);
			this.colorSlider = (this as UI_ColorSlider);
			this.colorPresets = (this as UI_ColorPresets);
		}

		// Token: 0x060022AB RID: 8875 RVA: 0x000D0898 File Offset: 0x000CEA98
		public void SetColor(HsvColor _hsv, UI_ColorInfo.ControlType ctrlType)
		{
			if (this.disableSetColor)
			{
				return;
			}
			this.colorValue[0] = _hsv.H;
			this.colorValue[1] = _hsv.S;
			this.colorValue[2] = _hsv.V;
			Color color = HsvColor.ToRgb(_hsv);
			this.colorValue[3] = color.r;
			this.colorValue[4] = color.g;
			this.colorValue[5] = color.b;
			this.SetColor(ctrlType);
		}

		// Token: 0x060022AC RID: 8876 RVA: 0x000D0918 File Offset: 0x000CEB18
		public void SetColor(Color _rgb, UI_ColorInfo.ControlType ctrlType)
		{
			if (this.disableSetColor)
			{
				return;
			}
			this.colorValue[3] = _rgb.r;
			this.colorValue[4] = _rgb.g;
			this.colorValue[5] = _rgb.b;
			this.colorValue[6] = _rgb.a;
			HsvColor hsvColor = HsvColor.FromRgb(_rgb);
			this.colorValue[0] = hsvColor.H;
			this.colorValue[1] = hsvColor.S;
			this.colorValue[2] = hsvColor.V;
			this.SetColor(ctrlType);
		}

		// Token: 0x060022AD RID: 8877 RVA: 0x000D09A8 File Offset: 0x000CEBA8
		public void SetAlpha(float _alpha, UI_ColorInfo.ControlType ctrlType)
		{
			if (this.disableSetColor)
			{
				return;
			}
			this.colorValue[6] = _alpha;
			this.SetColor(ctrlType);
		}

		// Token: 0x060022AE RID: 8878 RVA: 0x000D09C8 File Offset: 0x000CEBC8
		public void SetColor(UI_ColorInfo.ControlType ctrlType)
		{
			if (this.disableSetColor)
			{
				return;
			}
			this.disableSetColor = true;
			switch (ctrlType)
			{
			case UI_ColorInfo.ControlType.PickerRect:
				this.colorPicker.ChangePickerSliderColor();
				this.colorSlider.ChangeSliderSliderText(0);
				this.colorSlider.ChangeSliderSliderText(1);
				this.colorSlider.ChangeSliderSliderText(2);
				this.colorSlider.ChangeSliderSliderPos(0);
				this.colorSlider.ChangeSliderSliderPos(1);
				this.colorSlider.ChangeSliderSliderPos(2);
				this.colorSlider.ChangeSliderSliderColor(0);
				this.colorSlider.ChangeSliderSliderColor(1);
				this.colorSlider.ChangeSliderSliderColor(2);
				break;
			case UI_ColorInfo.ControlType.PickerSlider:
				this.colorPicker.ChangePickerRectColor();
				this.colorSlider.ChangeSliderSliderText(0);
				this.colorSlider.ChangeSliderSliderText(1);
				this.colorSlider.ChangeSliderSliderText(2);
				this.colorSlider.ChangeSliderSliderPos(0);
				this.colorSlider.ChangeSliderSliderPos(1);
				this.colorSlider.ChangeSliderSliderPos(2);
				this.colorSlider.ChangeSliderSliderColor(0);
				this.colorSlider.ChangeSliderSliderColor(1);
				this.colorSlider.ChangeSliderSliderColor(2);
				break;
			case UI_ColorInfo.ControlType.PickerSliderA:
				this.colorSlider.ChangeSliderSliderText(3);
				this.colorSlider.ChangeSliderSliderPos(3);
				break;
			case UI_ColorInfo.ControlType.SliderColor01:
				this.colorSlider.ChangeSliderSliderText(0);
				this.colorSlider.ChangeSliderSliderColor(1);
				this.colorSlider.ChangeSliderSliderColor(2);
				this.colorPicker.ChangePickerRectPos();
				this.colorPicker.ChangePickerSliderPos();
				this.colorPicker.ChangePickerRectColor();
				this.colorPicker.ChangePickerSliderColor();
				break;
			case UI_ColorInfo.ControlType.SliderColor02:
				this.colorSlider.ChangeSliderSliderText(1);
				this.colorSlider.ChangeSliderSliderColor(0);
				this.colorSlider.ChangeSliderSliderColor(2);
				this.colorPicker.ChangePickerRectPos();
				this.colorPicker.ChangePickerSliderPos();
				this.colorPicker.ChangePickerRectColor();
				this.colorPicker.ChangePickerSliderColor();
				break;
			case UI_ColorInfo.ControlType.SliderColor03:
				this.colorSlider.ChangeSliderSliderText(2);
				this.colorSlider.ChangeSliderSliderColor(0);
				this.colorSlider.ChangeSliderSliderColor(1);
				this.colorPicker.ChangePickerRectPos();
				this.colorPicker.ChangePickerSliderPos();
				this.colorPicker.ChangePickerRectColor();
				this.colorPicker.ChangePickerSliderColor();
				break;
			case UI_ColorInfo.ControlType.SliderAlpha:
				this.colorPicker.ChangePickerSliderAPos();
				this.colorSlider.ChangeSliderSliderText(3);
				break;
			case UI_ColorInfo.ControlType.InputColor01:
				this.colorSlider.ChangeSliderSliderPos(0);
				this.colorSlider.ChangeSliderSliderColor(1);
				this.colorSlider.ChangeSliderSliderColor(2);
				this.colorPicker.ChangePickerRectPos();
				this.colorPicker.ChangePickerSliderPos();
				this.colorPicker.ChangePickerRectColor();
				this.colorPicker.ChangePickerSliderColor();
				break;
			case UI_ColorInfo.ControlType.InputColor02:
				this.colorSlider.ChangeSliderSliderPos(1);
				this.colorSlider.ChangeSliderSliderColor(0);
				this.colorSlider.ChangeSliderSliderColor(2);
				this.colorPicker.ChangePickerRectPos();
				this.colorPicker.ChangePickerSliderPos();
				this.colorPicker.ChangePickerRectColor();
				this.colorPicker.ChangePickerSliderColor();
				break;
			case UI_ColorInfo.ControlType.InputColor03:
				this.colorSlider.ChangeSliderSliderPos(2);
				this.colorSlider.ChangeSliderSliderColor(0);
				this.colorSlider.ChangeSliderSliderColor(1);
				this.colorPicker.ChangePickerRectPos();
				this.colorPicker.ChangePickerSliderPos();
				this.colorPicker.ChangePickerRectColor();
				this.colorPicker.ChangePickerSliderColor();
				break;
			case UI_ColorInfo.ControlType.InputAlpha:
				this.colorSlider.ChangeSliderSliderPos(3);
				this.colorPicker.ChangePickerSliderAPos();
				break;
			case UI_ColorInfo.ControlType.PresetsSample:
				this.colorPicker.ChangePickerRectPos();
				this.colorPicker.ChangePickerSliderPos();
				this.colorPicker.ChangePickerRectColor();
				this.colorPicker.ChangePickerSliderColor();
				this.colorPicker.ChangePickerSliderAPos();
				this.colorSlider.ChangeSliderSliderText(0);
				this.colorSlider.ChangeSliderSliderText(1);
				this.colorSlider.ChangeSliderSliderText(2);
				this.colorSlider.ChangeSliderSliderText(3);
				this.colorSlider.ChangeSliderSliderPos(0);
				this.colorSlider.ChangeSliderSliderPos(1);
				this.colorSlider.ChangeSliderSliderPos(2);
				this.colorSlider.ChangeSliderSliderPos(3);
				this.colorSlider.ChangeSliderSliderColor(0);
				this.colorSlider.ChangeSliderSliderColor(1);
				this.colorSlider.ChangeSliderSliderColor(2);
				break;
			}
			if (this.imgColorSample)
			{
				this.imgColorSample.color = new Color(this.colorValue[3], this.colorValue[4], this.colorValue[5]);
			}
			if (this.imgColorSampleAlpha)
			{
				Vector3 localScale = default(Vector3);
				localScale = this.imgColorSampleAlpha.rectTransform.localScale;
				localScale.x = 1f - this.colorValue[6];
				this.imgColorSampleAlpha.rectTransform.localScale = localScale;
			}
			if (this.updateColorFunc != null)
			{
				Color color = new Color(this.colorValue[3], this.colorValue[4], this.colorValue[5], this.colorValue[6]);
				this.updateColorFunc(color);
			}
			this.disableSetColor = false;
		}

		// Token: 0x060022AF RID: 8879 RVA: 0x000D0EFC File Offset: 0x000CF0FC
		public string ConvertTextFromValue(UI_ColorInfo.ColorType type, float value)
		{
			int num = 0;
			switch (type)
			{
			case UI_ColorInfo.ColorType.Hue:
				num = (int)Mathf.Lerp(0f, 360f, value);
				break;
			case UI_ColorInfo.ColorType.Saturation:
			case UI_ColorInfo.ColorType.Value:
			case UI_ColorInfo.ColorType.Alpha:
				num = (int)Mathf.Lerp(0f, 100f, value);
				break;
			case UI_ColorInfo.ColorType.Red:
			case UI_ColorInfo.ColorType.Green:
			case UI_ColorInfo.ColorType.Blue:
				num = (int)Mathf.Lerp(0f, 255f, value);
				break;
			}
			return num.ToString();
		}

		// Token: 0x060022B0 RID: 8880 RVA: 0x000D0F8C File Offset: 0x000CF18C
		public float ConvertValueFromText(UI_ColorInfo.ColorType type, string buf, ref bool OutOfRange)
		{
			OutOfRange = false;
			int num = 0;
			if (string.Empty != buf)
			{
				num = int.Parse(buf);
			}
			float result = 0f;
			switch (type)
			{
			case UI_ColorInfo.ColorType.Hue:
				if (!MathfEx.RangeEqualOn<int>(0, num, 360))
				{
					OutOfRange = true;
				}
				num = Mathf.Clamp(num, 0, 360);
				result = Mathf.InverseLerp(0f, 360f, (float)num);
				break;
			case UI_ColorInfo.ColorType.Saturation:
			case UI_ColorInfo.ColorType.Value:
			case UI_ColorInfo.ColorType.Alpha:
				if (!MathfEx.RangeEqualOn<int>(0, num, 100))
				{
					OutOfRange = true;
				}
				num = Mathf.Clamp(num, 0, 100);
				result = Mathf.InverseLerp(0f, 100f, (float)num);
				break;
			case UI_ColorInfo.ColorType.Red:
			case UI_ColorInfo.ColorType.Green:
			case UI_ColorInfo.ColorType.Blue:
				if (!MathfEx.RangeEqualOn<int>(0, num, 255))
				{
					OutOfRange = true;
				}
				num = Mathf.Clamp(num, 0, 255);
				result = Mathf.InverseLerp(0f, 255f, (float)num);
				break;
			}
			return result;
		}

		// Token: 0x040023B6 RID: 9142
		public UI_ColorInfo.UpdateColor updateColorFunc;

		// Token: 0x040023B7 RID: 9143
		private float[] colorValue = new float[Enum.GetValues(typeof(UI_ColorInfo.ColorType)).Length];

		// Token: 0x040023B8 RID: 9144
		protected UI_ColorMenu colorMenu;

		// Token: 0x040023B9 RID: 9145
		protected UI_ColorPicker colorPicker;

		// Token: 0x040023BA RID: 9146
		protected UI_ColorSlider colorSlider;

		// Token: 0x040023BB RID: 9147
		protected UI_ColorPresets colorPresets;

		// Token: 0x040023BC RID: 9148
		protected bool disableSetColor;

		// Token: 0x040023BD RID: 9149
		public Image imgColorSample;

		// Token: 0x040023BE RID: 9150
		public Image imgColorSampleAlpha;

		// Token: 0x0200054D RID: 1357
		// (Invoke) Token: 0x060022B2 RID: 8882
		public delegate void UpdateColor(Color color);

		// Token: 0x0200054E RID: 1358
		public enum ControlType
		{
			// Token: 0x040023C0 RID: 9152
			PickerRect,
			// Token: 0x040023C1 RID: 9153
			PickerSlider,
			// Token: 0x040023C2 RID: 9154
			PickerSliderA,
			// Token: 0x040023C3 RID: 9155
			SliderColor01,
			// Token: 0x040023C4 RID: 9156
			SliderColor02,
			// Token: 0x040023C5 RID: 9157
			SliderColor03,
			// Token: 0x040023C6 RID: 9158
			SliderAlpha,
			// Token: 0x040023C7 RID: 9159
			InputColor01,
			// Token: 0x040023C8 RID: 9160
			InputColor02,
			// Token: 0x040023C9 RID: 9161
			InputColor03,
			// Token: 0x040023CA RID: 9162
			InputAlpha,
			// Token: 0x040023CB RID: 9163
			PresetsSample
		}

		// Token: 0x0200054F RID: 1359
		public enum ColorType
		{
			// Token: 0x040023CD RID: 9165
			Hue,
			// Token: 0x040023CE RID: 9166
			Saturation,
			// Token: 0x040023CF RID: 9167
			Value,
			// Token: 0x040023D0 RID: 9168
			Red,
			// Token: 0x040023D1 RID: 9169
			Green,
			// Token: 0x040023D2 RID: 9170
			Blue,
			// Token: 0x040023D3 RID: 9171
			Alpha
		}
	}
}
